﻿// Type: VSFile.Project.WebSiteDirectory
// Assembly: VSFile, Version=1.2.1.0, Culture=neutral, PublicKeyToken=null
// Assembly location: C:\Downloads\VSFile.dll

using System;
using System.Collections.Generic;
using System.IO;

namespace ReadSolutionContents
{
    /// <summary>
    /// Represents an ASP.NET web site directory.
    /// 
    /// </summary>
    public class WebSiteDirectory
    {
        /// <summary>
        /// Supported web site file extensions.
        /// 
        /// </summary>
        private static readonly string[] SupportedExtensions = new string[2]
    {
      ".vb",
      ".cs"
    };
        /// <summary>
        /// Visual Basic source files contained in this web site.
        /// 
        /// </summary>
        private List<BasicSourceFile> m_basicSourceFiles;
        /// <summary>
        /// Visual C# source files contained in this web site.
        /// 
        /// </summary>
        private List<CSharpSourceFile> m_cSharpSourceFiles;
        /// <summary>
        /// Path to directory containing web site files.
        /// 
        /// </summary>
        private string m_directoryPath;
        /// <summary>
        /// Web site name.
        /// 
        /// </summary>
        private string m_name;

        /// <summary>
        /// Get Visual Basic source files contained in this web site.
        /// 
        /// </summary>
        /// 
        /// <value>
        /// Enumerable collection of BasicSourceFile objects representing
        ///             Visual Basic source files contained in this web site.
        /// 
        /// </value>
        public IEnumerable<BasicSourceFile> BasicSourceFiles
        {
            get
            {
                return (IEnumerable<BasicSourceFile>)this.m_basicSourceFiles;
            }
        }

        /// <summary>
        /// Get Visual C# source files contained in this web site.
        /// 
        /// </summary>
        /// 
        /// <value>
        /// Enumerable collection of CSharpSourceFile objects representing
        ///             Visual C# source files contained in this web site.
        /// 
        /// </value>
        public IEnumerable<CSharpSourceFile> CSharpSourceFiles
        {
            get
            {
                return (IEnumerable<CSharpSourceFile>)this.m_cSharpSourceFiles;
            }
        }

        /// <summary>
        /// Get directory path.
        /// 
        /// </summary>
        /// 
        /// <value>
        /// String representing path to directory containing web site files.
        /// 
        /// </value>
        public string DirectoryPath
        {
            get
            {
                return this.m_directoryPath;
            }
        }

        /// <summary>
        /// Get web site name.
        /// 
        /// </summary>
        /// 
        /// <value>
        /// String representing web site name.
        /// 
        /// </value>
        public string Name
        {
            get
            {
                return this.m_name;
            }
        }

        static WebSiteDirectory()
        {
        }

        /// <summary>
        /// Constructor.
        /// 
        /// </summary>
        /// <param name="name">String representing web site name.
        ///             </param><param name="directoryPath">String representing path to directory containing web site files.
        ///             </param>
        public WebSiteDirectory(string name, string directoryPath)
        {
            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(directoryPath))
                throw new ArgumentException();
            this.m_basicSourceFiles = new List<BasicSourceFile>();
            this.m_cSharpSourceFiles = new List<CSharpSourceFile>();
            this.m_directoryPath = directoryPath;
            this.m_name = name;
        }

        /// <summary>
        /// Load web site files.
        /// 
        /// </summary>
        public void Load()
        {
            this.CheckDirectoryPath();
            this.ClearFiles();
            this.LoadFiles();
        }

        /// <summary>
        /// Throw exception if directory path is invalid.
        /// 
        /// </summary>
        private void CheckDirectoryPath()
        {
            if (!Directory.Exists(this.DirectoryPath))
                throw new DirectoryNotFoundException("Directory not found at path: " + this.DirectoryPath);
        }

        /// <summary>
        /// Clear web site files.
        /// 
        /// </summary>
        private void ClearFiles()
        {
            this.m_basicSourceFiles.Clear();
            this.m_cSharpSourceFiles.Clear();
        }

        /// <summary>
        /// Load web site files.
        /// 
        /// </summary>
        private void LoadFiles()
        {
            List<string> list = new List<string>();
            foreach (string fileExtension in WebSiteDirectory.SupportedExtensions)
            {
                string str = Path.Combine(this.DirectoryPath, Wildcard.AddAsterisk(fileExtension));
                list.Add(str);
            }
            VisualStudioFiles visualStudioFiles = new VisualStudioFiles((IEnumerable<string>)list, true);
            this.m_basicSourceFiles.AddRange(visualStudioFiles.BasicSourceFiles);
            this.m_cSharpSourceFiles.AddRange(visualStudioFiles.CSharpSourceFiles);
        }
    }
}
